﻿@using FujiyBlog.Web.Extensions
@model FujiyBlog.Web.ViewModels.PostArchive
           
@{
    ViewBag.Title = Resources.Labels.Archive;
    Layout = this.FindLayoutPath("_Layout");
}

<div id="archive">
    <h1>
        @Resources.Labels.Archive</h1>
    <ul>
        @foreach (FujiyBlog.Core.DomainObjects.Category category in Model.AllCategories)
        {
            <li><a href="#@category.Id">@category.Name</a></li>
        }
        <li><a href="#Uncategorized">@Resources.Labels.Uncategorized</a></li>
    </ul>
    @foreach (FujiyBlog.Core.DomainObjects.Category category in Model.AllCategories)
    {
        <h2 id="@category.Id">
            @category.Name (@category.Posts.Count())
        </h2>
            

        <table>
            <tr>
                <th>
                    @Resources.Labels.Date
                </th>
                <th>
                    @Resources.Labels.Title
                </th>
                <th class="comments">
                    @Resources.Labels.Comments
                </th>
            </tr>
            @foreach (FujiyBlog.Core.Dto.PostSummary postSummary in Model.AllPosts.Where(x => x.Post.Categories.Any(y => y == category)))
            {
                <tr>
                    <td class="date">@FujiyBlog.Web.Common.DateTimeUtil.ConvertUtcToMyTimeZone(postSummary.Post.PublicationDate).ToShortDateString()
                    </td>
                    <td class="title">@Html.ActionLink(postSummary.Post.Title, MVC.Post.Details(postSummary.Post.Slug))
                    </td>
                    <td class="comments">@postSummary.CommentsTotal
                    </td>
                </tr>  
            }
        </table>
    }

     <h2 id="Uncategorized">
            @Resources.Labels.Uncategorized (@Model.UncategorizedPosts.Count())
        </h2>
            

        <table>
            <tr>
                <th>
                    @Resources.Labels.Date
                </th>
                <th>
                    @Resources.Labels.Title
                </th>
                <th class="comments">
                    @Resources.Labels.Comments
                </th>
            </tr>
            @foreach (FujiyBlog.Core.Dto.PostSummary postSummary in Model.UncategorizedPosts)
            {
                <tr>
                    <td class="date">@FujiyBlog.Web.Common.DateTimeUtil.ConvertUtcToMyTimeZone(postSummary.Post.PublicationDate).ToShortDateString()
                    </td>
                    <td class="title">@Html.ActionLink(postSummary.Post.Title, MVC.Post.Details(postSummary.Post.Slug))
                    </td>
                    <td class="comments">@postSummary.CommentsTotal
                    </td>
                </tr>  
            }
        </table>
</div>
